#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int sumB(TreeNode* root, int val)
    {
        if (root == nullptr) return 0;
        val = (val << 1) | root->val;
        if (root->right == nullptr && root->left == nullptr) return val;

        return sumB(root->left, val) + sumB(root->right, val);
    }
    int sumRootToLeaf(TreeNode* root)
    {
        return sumB(root, 0);
    }
};